using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace DocumentManagement
{
  /// <summary>
  /// Tdoctran Data Object Class
  /// </summary>
  public partial class DOTdoctran
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Tdoctran d_id
		/// </summary>
		public const string Rowd_id = "d_id";

		/// <summary>
		/// The Table Column for the Tdoctran d_datetime
		/// </summary>
		public const string Rowd_datetime = "d_datetime";

		/// <summary>
		/// The Table Column for the Tdoctran d_status
		/// </summary>
		public const string Rowd_status = "d_status";

		/// <summary>
		/// The Table Column for the Tdoctran d_descrip
		/// </summary>
		public const string Rowd_descrip = "d_descrip";

		/// <summary>
		/// The Table Column for the Tdoctran d_releasetype
		/// </summary>
		public const string Rowd_releasetype = "d_releasetype";

		/// <summary>
		/// The Table Column for the Tdoctran d_releasereason
		/// </summary>
		public const string Rowd_releasereason = "d_releasereason";

		/// <summary>
		/// The Table Column for the Tdoctran d_primaryattorney
		/// </summary>
		public const string Rowd_primaryattorney = "d_primaryattorney";

		/// <summary>
		/// The Table Column for the Tdoctran d_secondaryattorney
		/// </summary>
		public const string Rowd_secondaryattorney = "d_secondaryattorney";

		/// <summary>
		/// The Table Column for the Tdoctran d_releasedate
		/// </summary>
		public const string Rowd_releasedate = "d_releasedate";

		/// <summary>
		/// The Table Column for the Tdoctran d_returndate
		/// </summary>
		public const string Rowd_returndate = "d_returndate";

		/// <summary>
		/// The Table Column for the Tdoctran d_primaryattorneyletterreference
		/// </summary>
		public const string Rowd_primaryattorneyletterreference = "d_primaryattorneyletterreference";

		/// <summary>
		/// The Table Column for the Tdoctran d_secondaryattorneyletterreference
		/// </summary>
		public const string Rowd_secondaryattorneyletterreference = "d_secondaryattorneyletterreference";

		/// <summary>
		/// The Table Column for the Tdoctran d_trackingnumber
		/// </summary>
		public const string Rowd_trackingnumber = "d_trackingnumber";

		/// <summary>
		/// The Table Column for the Tdoctran d_user
		/// </summary>
		public const string Rowd_user = "d_user";

		/// <summary>
		/// The Table Column for the Tdoctran d_workstation
		/// </summary>
		public const string Rowd_workstation = "d_workstation";

		/// <summary>
		/// The Table Column for the Tdoctran d_uniqueid
		/// </summary>
		public const string Rowd_uniqueid = "d_uniqueid";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spTdoctran_Create";
private const string m_StoredProcedureConstDelete = "spTdoctran_Delete";
private const string m_StoredProcedureConstRetrieve = "spTdoctran_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spTdoctran_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spTdoctran_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private string m_d_id;
		private DateTime m_d_datetime;
		private string m_d_status;
		private string m_d_descrip;
		private string m_d_releasetype;
		private string m_d_releasereason;
		private string m_d_primaryattorney;
		private string m_d_secondaryattorney;
		private DateTime m_d_releasedate;
		private DateTime m_d_returndate;
		private string m_d_primaryattorneyletterreference;
		private string m_d_secondaryattorneyletterreference;
		private string m_d_trackingnumber;
		private string m_d_user;
		private string m_d_workstation;
		private string m_d_uniqueid;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOTdoctran> m_Tdoctrans = new List<DOTdoctran>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOTdoctran() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// d_id
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_id
		/// </remarks>
		public string d_id
		{
			get { return (this.m_d_id); }
			set { this.m_d_id = value; }
		}

		/// <summary>
		/// d_datetime
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_datetime
		/// </remarks>
		public DateTime d_datetime
		{
			get { return (this.m_d_datetime); }
			set { this.m_d_datetime = value; }
		}

		/// <summary>
		/// d_status
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_status
		/// </remarks>
		public string d_status
		{
			get { return (this.m_d_status); }
			set { this.m_d_status = value; }
		}

		/// <summary>
		/// d_descrip
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_descrip
		/// </remarks>
		public string d_descrip
		{
			get { return (this.m_d_descrip); }
			set { this.m_d_descrip = value; }
		}

		/// <summary>
		/// d_releasetype
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_releasetype
		/// </remarks>
		public string d_releasetype
		{
			get { return (this.m_d_releasetype); }
			set { this.m_d_releasetype = value; }
		}

		/// <summary>
		/// d_releasereason
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_releasereason
		/// </remarks>
		public string d_releasereason
		{
			get { return (this.m_d_releasereason); }
			set { this.m_d_releasereason = value; }
		}

		/// <summary>
		/// d_primaryattorney
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_primaryattorney
		/// </remarks>
		public string d_primaryattorney
		{
			get { return (this.m_d_primaryattorney); }
			set { this.m_d_primaryattorney = value; }
		}

		/// <summary>
		/// d_secondaryattorney
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_secondaryattorney
		/// </remarks>
		public string d_secondaryattorney
		{
			get { return (this.m_d_secondaryattorney); }
			set { this.m_d_secondaryattorney = value; }
		}

		/// <summary>
		/// d_releasedate
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_releasedate
		/// </remarks>
		public DateTime d_releasedate
		{
			get { return (this.m_d_releasedate); }
			set { this.m_d_releasedate = value; }
		}

		/// <summary>
		/// d_returndate
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_returndate
		/// </remarks>
		public DateTime d_returndate
		{
			get { return (this.m_d_returndate); }
			set { this.m_d_returndate = value; }
		}

		/// <summary>
		/// d_primaryattorneyletterreference
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_primaryattorneyletterreference
		/// </remarks>
		public string d_primaryattorneyletterreference
		{
			get { return (this.m_d_primaryattorneyletterreference); }
			set { this.m_d_primaryattorneyletterreference = value; }
		}

		/// <summary>
		/// d_secondaryattorneyletterreference
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_secondaryattorneyletterreference
		/// </remarks>
		public string d_secondaryattorneyletterreference
		{
			get { return (this.m_d_secondaryattorneyletterreference); }
			set { this.m_d_secondaryattorneyletterreference = value; }
		}

		/// <summary>
		/// d_trackingnumber
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_trackingnumber
		/// </remarks>
		public string d_trackingnumber
		{
			get { return (this.m_d_trackingnumber); }
			set { this.m_d_trackingnumber = value; }
		}

		/// <summary>
		/// d_user
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_user
		/// </remarks>
		public string d_user
		{
			get { return (this.m_d_user); }
			set { this.m_d_user = value; }
		}

		/// <summary>
		/// d_workstation
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_workstation
		/// </remarks>
		public string d_workstation
		{
			get { return (this.m_d_workstation); }
			set { this.m_d_workstation = value; }
		}

		/// <summary>
		/// d_uniqueid
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctran d_uniqueid
		/// </remarks>
		public string d_uniqueid
		{
			get { return (this.m_d_uniqueid); }
			set { this.m_d_uniqueid = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOTdoctran> Tdoctrans
	{
	  get { return m_Tdoctrans; }
	  set { m_Tdoctrans = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public DataSet Retrieve()
    {
      DataSet returnDS = new DataSet();
      sqlData = new SQLDataObject();
      sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + Rowd_id + "=" + this.d_id);
      return returnDS;
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    public bool Update()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[Rowd_id].ToString() != "")
			this.d_id = dr[Rowd_id].ToString();

		if (dr[Rowd_datetime].ToString() != "")
			this.d_datetime = DateTime.Parse(dr[Rowd_datetime].ToString());

		if (dr[Rowd_status].ToString() != "")
			this.d_status = dr[Rowd_status].ToString();

		if (dr[Rowd_descrip].ToString() != "")
			this.d_descrip = dr[Rowd_descrip].ToString();

		if (dr[Rowd_releasetype].ToString() != "")
			this.d_releasetype = dr[Rowd_releasetype].ToString();

		if (dr[Rowd_releasereason].ToString() != "")
			this.d_releasereason = dr[Rowd_releasereason].ToString();

		if (dr[Rowd_primaryattorney].ToString() != "")
			this.d_primaryattorney = dr[Rowd_primaryattorney].ToString();

		if (dr[Rowd_secondaryattorney].ToString() != "")
			this.d_secondaryattorney = dr[Rowd_secondaryattorney].ToString();

		if (dr[Rowd_releasedate].ToString() != "")
			this.d_releasedate = DateTime.Parse(dr[Rowd_releasedate].ToString());

		if (dr[Rowd_returndate].ToString() != "")
			this.d_returndate = DateTime.Parse(dr[Rowd_returndate].ToString());

		if (dr[Rowd_primaryattorneyletterreference].ToString() != "")
			this.d_primaryattorneyletterreference = dr[Rowd_primaryattorneyletterreference].ToString();

		if (dr[Rowd_secondaryattorneyletterreference].ToString() != "")
			this.d_secondaryattorneyletterreference = dr[Rowd_secondaryattorneyletterreference].ToString();

		if (dr[Rowd_trackingnumber].ToString() != "")
			this.d_trackingnumber = dr[Rowd_trackingnumber].ToString();

		if (dr[Rowd_user].ToString() != "")
			this.d_user = dr[Rowd_user].ToString();

		if (dr[Rowd_workstation].ToString() != "")
			this.d_workstation = dr[Rowd_workstation].ToString();

		if (dr[Rowd_uniqueid].ToString() != "")
			this.d_uniqueid = dr[Rowd_uniqueid].ToString();
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOTdoctran Tdoctran = new DOTdoctran();
			
					if (dr[Rowd_id].ToString() != "")
			Tdoctran.d_id = dr[Rowd_id].ToString();

		if (dr[Rowd_datetime].ToString() != "")
			Tdoctran.d_datetime = DateTime.Parse(dr[Rowd_datetime].ToString());

		if (dr[Rowd_status].ToString() != "")
			Tdoctran.d_status = dr[Rowd_status].ToString();

		if (dr[Rowd_descrip].ToString() != "")
			Tdoctran.d_descrip = dr[Rowd_descrip].ToString();

		if (dr[Rowd_releasetype].ToString() != "")
			Tdoctran.d_releasetype = dr[Rowd_releasetype].ToString();

		if (dr[Rowd_releasereason].ToString() != "")
			Tdoctran.d_releasereason = dr[Rowd_releasereason].ToString();

		if (dr[Rowd_primaryattorney].ToString() != "")
			Tdoctran.d_primaryattorney = dr[Rowd_primaryattorney].ToString();

		if (dr[Rowd_secondaryattorney].ToString() != "")
			Tdoctran.d_secondaryattorney = dr[Rowd_secondaryattorney].ToString();

		if (dr[Rowd_releasedate].ToString() != "")
			Tdoctran.d_releasedate = DateTime.Parse(dr[Rowd_releasedate].ToString());

		if (dr[Rowd_returndate].ToString() != "")
			Tdoctran.d_returndate = DateTime.Parse(dr[Rowd_returndate].ToString());

		if (dr[Rowd_primaryattorneyletterreference].ToString() != "")
			Tdoctran.d_primaryattorneyletterreference = dr[Rowd_primaryattorneyletterreference].ToString();

		if (dr[Rowd_secondaryattorneyletterreference].ToString() != "")
			Tdoctran.d_secondaryattorneyletterreference = dr[Rowd_secondaryattorneyletterreference].ToString();

		if (dr[Rowd_trackingnumber].ToString() != "")
			Tdoctran.d_trackingnumber = dr[Rowd_trackingnumber].ToString();

		if (dr[Rowd_user].ToString() != "")
			Tdoctran.d_user = dr[Rowd_user].ToString();

		if (dr[Rowd_workstation].ToString() != "")
			Tdoctran.d_workstation = dr[Rowd_workstation].ToString();

		if (dr[Rowd_uniqueid].ToString() != "")
			Tdoctran.d_uniqueid = dr[Rowd_uniqueid].ToString();

            this.Tdoctrans.Add(Tdoctran);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
